import utils from './../utils'
import * as types from '../constants/goods'
import store from 'store'




//读取商品详情
export const getGoodsInfo =(data,config={})=>{
	data= {...data,...{func:'product-detail',store_id:0}}
    return (dispatch,getState)=>{
    	const options = getState().goodsInfo.toJS()
    	if(options.goods_id == data.goods_id)  return dispatch({type:types.GET_GOODS_INFO,data:options})
		return utils.form(utils.url.index,data)
		.then(res=>{
			return dispatch({type:types.GET_GOODS_INFO,data:res.data||{}})
		})
	}
}

//读取附属商品详情
export const getSubGoodsInfo =(data,config={})=>{
	data= {...data,...{func:'product-detail',store_id:0}}
    return (dispatch,getState)=>{
    	const options = getState().subGoodsInfo.toJS()
    	if(options.goods_id == data.goods_id)  return dispatch({type:types.GET_SUB_GOODS_INFO,data:options})
		return utils.form(utils.url.index,data)
		.then(res=>{
			return dispatch({type:types.GET_SUB_GOODS_INFO,data:res.data})
		})
	}
}








































